<template>
<div>
     
       <el-upload
  list-type="picture-card"
  :multiple="true"
  action="''"
  :http-request="upload"
   :file-list="fileList"
  :before-upload="beforeAvatarUpload">
  <i class="el-icon-plus"></i>
 </el-upload>


<div style="margin-top:25px">
    <el-row >
         <el-col :span="2" :offset="14">  <el-button size="medium" type="Success" plain @click="upload()">提交</el-button></el-col>
</el-row>
   
</div>
</div>
 
</template>

<script>

export default ({
  data(){
    return {
      
      
 fileList:[],
      
     dialogImageUrl: '',
        dialogVisible: false
    }
  },
 // created:function() {
//     var bwid = this.$route.query.bwid;
 //       this.allFile();
     
       
 //},
   methods:{
  
        
      // getInfoByBoid() {
      //     console.log("bwid:"+this.$route.query.bwid)
      //        this.$axios.post("http://localhost:8082/loan/getInfoByBoid", {
               
      //                boid: this.$route.query.bwid,
      //       }).then(resp=>{
      //           console.log(resp.data);
                
      //       });
      // },
       handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
    //   查看所有文件
    allFile(){
          console.log("abc:"+this.fileList)
        this.$axios.get("http://localhost:8082/file/allFile",{

        }).then(resp=>{
            console.log(resp.data.data)
         resp.data.data.forEach(element => {
             this.fileList.push(element)
         });
           this.fileList=resp.data
        })
    },
    //   上传文件
      upload(fileList){
      //获取文件
    //   let file = document.getElementById("file").files[0];
    let file = fileList.file;
    console.log(fileList)
      console.log(file);
      //将file封装到formdata
      let formData = new FormData();
      formData.append("file",file);
      //上传
      this.$axios.post("http://localhost:8082/file/upload",formData,{
        headers:{
          'Content-Type':'multipart/form-data'
        }
      }).then(res => {
        console.log(res.data);
      })
    
      },
           beforeAvatarUpload(file) {
        const isLt2M = file.size / 1024 / 1024 < 2;

       
        if (!isLt2M) {
          this.$message.error('上传文件大小不能超过 2MB!');
        }
        return  isLt2M;
      }
  },
  
})
</script>

<style>

      .el-row {
    margin-bottom: 20px;
  
  }
  /* .el-col {
    border-radius: 4px;
  } */
  .bg-purple-dark {
    background: #99a9bf;
  }
  .bg-purple {
    background: #d3dce6;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
</style>
